package org.jproxy;

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

class InstanceInfo
{
	private final Object instance;
	private final Class<?> instanceClass;
	private final Map<String, List<Method>> methodMap;

	InstanceInfo(Object instance)
	{
		this.instance = instance;
		instanceClass = instance.getClass();
		methodMap = initMethodMap();
	}

	private Map<String, List<Method>> initMethodMap()
	{
		Map<String, List<Method>> map = new HashMap<String, List<Method>>();
		for(Method method : instanceClass.getDeclaredMethods())
		{
			String name = method.getName();
			List<Method> methodList = map.get(name);
			if(methodList == null)
				methodList = new ArrayList<Method>();
			methodList.add(method);
			map.put(name, methodList);
		}
		return Collections.unmodifiableMap(map);
	}

	Object getInstance()
	{
		return instance;
	}

	@SuppressWarnings("unchecked")
	Class getInstanceClass()
	{
		return instanceClass;
	}

	List<Method> getMethodList(String name)
	{
		return methodMap.get(name);
	}

}
